home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / wink24h / src / wink2.c < prev    next >
Text File  |  1994-06-01  |  18KB  |  664 lines

  1. /************************************************************
  2.  
  3.     FM-TOWNS Text Screen Editer Program
  4.  
  5.     1989.7.27   v1.00   Make By Ken
  6.  
  7. ************************************************************/
  8. #include    <stdio.h>
  9. #include    <stdlib.h>
  10. #include    <setjmp.h>
  11. #include    <string.h>
  12. #define MAIN
  13. #include    "defs.h"
  14.  
  15. #ifdef    FMR70
  16. #include    <signal.h>
  17. #endif
  18.  
  19. #ifdef  TOWNS
  20. #include    <egb.h>
  21. #include    <snd.h>
  22. #include    <fmcfrb.h>
  23. #include    <kkstr2.h>
  24. #define    unlink(f) remove(f)
  25. #endif
  26. /* ------------------ SIDEWORK 92.01.31 Pumpkin ------------- */
  27. #include    <mos.h>
  28. #include    <sidework.h>
  29. /* ---------------------------------------------------------- */
  30. /* ------------------ KYB init 92.03.20 Pumpkin ------------- */
  31. #include    "int24.h"
  32. /* ---------------------------------------------------------- */
  33. /* ------------------ Debug  92.02.07 Pumpkin --------------- */
  34. extern int  diskReady(int drive);
  35. extern    int    retdir(char *name);
  36. extern    int    chdir(char *name);
  37. /* ---------------------------------------------------------- */
  38. /* --------------- Color Pal   91.12.29 Pumpkin ------------- */
  39. void pal_init(char *pal_file);
  40. /* ---------------------------------------------------------- */
  41. /* ------------------ SIDEWORK 92.01.31 Pumpkin ------------- */
  42. char     *mwork;
  43. static    int vol,mute;
  44. /* ---------------------------------------------------------- */
  45.  
  46. /* ------------------ OAK4 91.12.28 Pumpkin ----------------- */
  47. /* ------------------ OAK4 92.12.28 Pumpkin ----------------- */
  48. #include    <dos.h>
  49. int modeW = KAN_EISYOU | KAN_EISUU | KAN_HANKAKU;
  50. /* ---------------------------------------------------------- */
  51. /* ------------------ CD No Stop 91.10.18 Pumpkin ----------- */
  52. #ifdef    TOWNS
  53. extern     int    cd_stop;
  54. #endif
  55. /* ---------------------------------------------------------- */
  56.  
  57. /* --------------------- EUP play 92.03.30 ------------------ */
  58. #ifdef    TOWNS
  59. char     *swork;
  60. #define BUFF_SIZE (66000)    /* customaized by YAMA */
  61. extern int ML_Start( char * ,int , char * );
  62. extern int ML_End();
  63. extern char buff[];
  64. #endif
  65. /* ---------------------------------------------------------- */
  66.  
  67. extern void wrtstr();
  68. extern void Dsp_ins_mode();
  69. extern void Dsp_free();
  70. extern void Ins_buf();
  71. extern void Cut_buf();
  72. extern int  Dsp_init();
  73. extern int  Bfp_init();
  74. extern void Set_vram();
  75. extern void Dsp_vram();
  76. extern BOOL edit();
  77. extern int  Del_wind();
  78. extern void Bfp_end();
  79. extern void RSB_end();
  80. extern void Dmy_form();
  81. extern void Del_buf();
  82. extern void Auto_log_init();
  83. extern void CD_endof();
  84.  
  85. extern UCHAR vram[];
  86. extern char  *SPCSTR;
  87. extern char  *Auto_log_file;
  88.  
  89. /* ------------------ OAK4 91.12.28 Pumpkin ----------------- */
  90. /*******
  91. extern short int modeW;
  92. *******/
  93. /* ---------------------------------------------------------- */
  94.  
  95.     char     *work;
  96.     jmp_buf mark;
  97.     char    *file_name=NULL;
  98.     char    *Tmp_device_name=NULL;
  99.  
  100. static BOOL    old_wrt_flg=ERR;
  101. static char     tmp_name[160];
  102. static int    Back_up = FALSE;
  103. static int    Apend_Z = FALSE;
  104.  
  105. void    Start_Msg()
  106. {
  107.     static char *msg[]={
  108.     "           WINK @ー            ",
  109.     "   Multi Screen Text Editor   ",
  110.     "    WINK海賊版[ver1.24]   ",
  111.     " Copyright (c) 1989-93 FTOWNS ",
  112.     "    Created by K.Miyazaki     ",
  113.     "       thanks to RED++        ",
  114.     "    customaized by Pumpkin    ",
  115.     NULL
  116.     };
  117.     int     i;
  118.     char    tmp[160];
  119.  
  120.     Dmy_form(tmp,30,0x98,0x95,0x99); 
  121.     wrtstr(tmp,20,9,0x07);
  122.     Dmy_form(tmp,30,0x96,0x20,0x96); 
  123.     for ( i = 0 ; msg[i] != NULL ; i++ ) {
  124.         wrtstr(tmp,20,10+i,0x07);
  125.         wrtstr(msg[i],21,10+i,i == 0 ? 0x14 : 0x07);
  126.     }
  127.     Dmy_form(tmp,30,0x9A,0x95,0x9B); 
  128.     wrtstr(tmp,20,17,0x07);
  129.     wrtstr("WINK",25,12,0x16);
  130. }
  131.  
  132. void    GetDspPos(int *x, int *y)
  133. {
  134.     *x = (OFF_X + Cur_X) * 8;
  135.     *y = (OFF_Y + Cur_Y) * 16;
  136. }
  137.  
  138. void    Tango_Touroku(char *str);
  139.  
  140. /* ------------------ OAK4 91.12.28 Pumpkin ----------------- */
  141. void    Gra_init(int kan_sw)
  142. /*****
  143. void    Gra_init()
  144. ******/
  145. /* ---------------------------------------------------------- */
  146. {
  147. #ifdef    TOWNS
  148.     KANJ    kana;
  149. /* ------------------ OAK4 91.12.28 Pumpkin ----------------- */
  150.     static union REGS    reg;
  151.     int     col[16];
  152. /* ---------------------------------------------------------- */
  153.  
  154.     work = (char *)malloc(EgbWorkSize);
  155.     memset(work,0,EgbWorkSize);
  156. /* --------------------- EUP play 92.03.30 ------------------ */
  157.     swork = (char *)malloc(16384);        /* customaized by YAMA */
  158.     memset(swork,0,16384);            /* customaized by YAMA */
  159. /* ---------------------------------------------------------- */
  160.     EGB_init(work,EgbWorkSize);
  161.     EGB_resolution(work, 0, 3);
  162.     EGB_resolution(work, 1, 3);
  163.     EGB_displayPage(work, 1, 3);
  164.     EGB_pen(work,0);
  165.     EGB_penSize(work,1);
  166. /* ------------------ SIDEWORK 92.02.14 Pumpkin ------------- */
  167.     SND_elevol_read(1,&vol,&vol);
  168.     SND_get_elevol_mute(&mute);
  169. /* ---------------------------------------------------------- */
  170. /* --------------------- EUP play 92.03.30 ------------------ */
  171.     SND_init(swork);            /* customaized by YAMA */
  172. /* ---------------------------------------------------------- */
  173. /* ------------------ SIDEWORK 92.02.14 Pumpkin ------------- */
  174.     SND_elevol_set(1,vol,vol);
  175.     SND_elevol_mute(mute | 0x33);
  176. /******
  177.     SND_elevol_init();
  178.     SND_elevol_mute(0x30);
  179.     SND_elevol_set(1,64,64);
  180. ******/
  181. /* ---------------------------------------------------------- */
  182. /* --------------------- EUP play 92.03.30 ------------------ */
  183.     ML_Start(buff,BUFF_SIZE,swork);        /* customaized by YAMA */
  184. /* ---------------------------------------------------------- */
  185.  
  186.     kana.scrn   = KAN_SCRN16;   /*  画面モードは16色モード               */
  187.     kana.egbw   = work;         /*  EGBのワークアドレスを設定する            */
  188.     kana.wPage  = 0;            /*  表示ページを1にする                */
  189.     kana.mosAp  = KAN_MOSON;    /*  マウスの制御をする                 */
  190.     kana.gets   = Tango_Touroku;/*  文字取得ルーチンの設定                 */
  191.     kana.getPos = GetDspPos;    /*  未確定文字列表示位置取得関数の設定 */
  192.     kana.maxX   = 639;          /*  画面の最大X座標                    */
  193.     kana.maxY   = 479;          /*  画面の最大Y座標                    */
  194.  
  195.     KAN_prepare(&kana);
  196.  
  197. /* ------------------ OAK4 91.12.28 Pumpkin ----------------- */
  198.     /*  従来のWINKライクなカラーテーブルの設定 */
  199.     col[ 0] = 0x0f;
  200.     col[ 1] = 0x01;
  201.     col[ 2] = 0x02;
  202.     col[ 3] = 0x03;
  203.     col[ 4] = 0x04;
  204.     col[ 5] = 0x05;
  205.     col[ 6] = 0x06;
  206.     col[ 7] = 0x00;
  207.     col[ 8] = 0x08;
  208.     col[ 9] = 0x09;
  209.     col[10] = 0x0a;
  210.     col[11] = 0x0b;
  211.     col[12] = 0x04;
  212.     col[13] = 0x06;
  213.     col[14] = 0x03;
  214.     col[15] = 0x01;
  215.     KAN_setClrTbl( col);
  216.  
  217. /* ---------------------------------------------------------- */
  218.     KAN_disp(KAN_DISPON);
  219.  
  220. /* ------------------ OAK4 91.12.28 Pumpkin ----------------- */
  221. /* ------------------ OAK4 92.12.28 Pumpkin ----------------- */
  222.     /* OAK入力モード設定 */
  223.  
  224.     if (kan_sw != FALSE) {
  225.     KAN_setMode(modeW);
  226.     }
  227. /* ---------------------------------------------------------- */
  228.  
  229.  
  230. #endif
  231. }
  232. void    Dsp_file_name()
  233. {
  234.     char    tmp[160];
  235.  
  236.     memset(tmp,' ',60); tmp[60] = '\0';
  237.     wrtstr(tmp,0,1,0x1F);
  238.     if ( file_name != NULL ) {
  239.     sprintf(tmp," %-12s ",file_name);
  240.     wrtstr(tmp,0,1,0x14);
  241.     } else
  242.     wrtstr("  [Not File]  ",1,1,0x1F);
  243. }
  244. void    Dsp_wrt_flg()
  245. {
  246.     if ( Wrt_flg != old_wrt_flg ) {
  247.     if ( (old_wrt_flg = Wrt_flg) == FALSE )
  248.         wrtstr("表示",0,0,0x17);
  249.     else
  250.         wrtstr("編集",0,0,0x17);
  251.     }
  252. }
  253. void    Dsp_PFKEY()
  254. {
  255.     int     i;
  256.     static char *menu[]={
  257.     " MENU1"," MENU2"," MENU3"," MENU4","CD演奏",
  258.     " 選択 "," 削除 "," 確定 "," 複写 "," 通信 " };
  259.  
  260.     for ( i = 0 ; i < 10 ; i++ )
  261.         wrtstr(menu[i],i*7+(i/5),MENU_Y,0x1F);
  262. }
  263. void    Dsp_status()
  264. {
  265.     UCHAR   tmp[100];
  266.  
  267.     memset(tmp,' ',80); tmp[80] = '\0';
  268.     wrtstr(tmp,0,0,0x1F);
  269.     wrtstr(tmp,0,1,0x1F);
  270.     Dsp_ins_mode();
  271.     Dsp_file_name();
  272.     Dsp_wrt_flg();
  273.     Dsp_free();
  274.     Dsp_PFKEY();
  275. }
  276. int     Buf_init(file)
  277. char    *file;
  278. {
  279.     int        n;
  280.     FILE    *fp;
  281.     UCHAR   tmp[512];
  282.  
  283.     top_ptr = lin_ptr = ent_ptr = btm_ptr = 0;
  284.     if ( file != (char *)NULL && (fp = fopen(file,"rb")) != (FILE *)NULL ) {
  285.     wrtstr("ファイルを読み込んでいます",30,1,0x15);
  286.     while ( (n = fread(tmp,1,512,fp)) > 0 ) {
  287.         Ins_buf(btm_ptr,n,tmp);
  288.         btm_ptr += n;
  289.     }
  290.     if ( btm_ptr > 0 && *Cnv_ptr(btm_ptr-1) == '\x1A' )
  291.         Del_buf(--btm_ptr,1L);
  292.     file_name = file;
  293.     fclose(fp);
  294.     wrtstr(SPCSTR,30,1,0x1F);
  295.     } else
  296.     file_name = file;
  297.  
  298.     chk_ptr = cke_ptr = ERR;
  299.     Wrt_flg = FALSE;
  300.     old_wrt_flg = TRUE;
  301.  
  302.     return FALSE;
  303. }
  304. int    save(file)
  305. char    *file;
  306. {
  307.     FILE    *fp;
  308.     UCHAR   tmp[256];
  309.     int        n;
  310.     LONG    sp,sz;
  311.     char    *p;
  312.  
  313.     if ( file != NULL ) {
  314.     file_name = file;
  315.     Dsp_file_name();
  316.     }
  317.     if ( file_name == NULL )
  318.     return ERR;
  319.  
  320.     if ( Back_up != FALSE ) {
  321.     strcpy((char *)tmp,file_name);
  322.     if ( (p = strrchr((char *)tmp,'.')) == NULL )
  323.         for ( p = (char *)tmp ; *p != '\0' ; p++ );
  324.     strcpy(p,".BAK");
  325.     unlink((char *)tmp);
  326.     rename(file_name,(char *)tmp);
  327.     }
  328.  
  329.     if ( (fp = fopen(file_name,"wb")) == NULL )
  330.     return ERR;
  331.  
  332.     for ( sp = 0,sz = btm_ptr ; sz > 0 ; ) {
  333.     if ( sz < 256 ) n = sz; else n = 256;
  334.         Cut_buf(tmp,n,sp);
  335. /* ------------------ bug fix  93.02.18 Pumpkin ---------------- */
  336.     if (fwrite(tmp,1,n,fp) == 0) break;
  337. /* -------------------------------------------------------------- */
  338. /**********
  339.     fwrite(tmp,1,n,fp);
  340. **********/
  341.     sp += n;
  342.     sz -= n;
  343.     }
  344.  
  345.     if ( Apend_Z == FALSE ) {
  346.     tmp[0] = 0x1A;
  347.     fwrite(tmp,1,1,fp);
  348.     }
  349.  
  350.     if ( ferror(fp) ) {
  351.     fclose(fp);
  352.     return ERR;
  353.     }
  354.     fclose(fp);
  355.     return FALSE;
  356. }
  357. void    Set_file_name(file)
  358. char    *file;
  359. {
  360.     strcpy(tmp_name,file);
  361.     file_name = tmp_name;
  362.     Dsp_file_name();
  363. }
  364. void    Set2_file_name(file)
  365. char    *file;
  366. {
  367.     strcpy(tmp_name,file);
  368.     file_name = tmp_name;
  369. }
  370. void    main(argc,argv)
  371. int    argc;
  372. char    *argv[];
  373. {
  374.     int     i;
  375.     char    tmp[40];
  376.     char    *p;
  377.     char    *file=NULL;
  378.  
  379.     CONTRL = 0;
  380.     TAB = 8;
  381. /* ------------------ Debug  92.02.07 Pumpkin --------------- */
  382.     char    firstdir[128];
  383. /* ---------------------------------------------------------- */
  384. /* ------------------ OAK4 91.12.28 Pumpkin ----------------- */
  385.     int kan_mode = FALSE;
  386. /* ---------------------------------------------------------- */
  387. /* --------------- Color Pal   91.08.28 Pumpkin ------------- */
  388.     char    *pal_file = NULL;
  389. /* ---------------------------------------------------------- */
  390. /* ------------------ KYB init 92.03.20 Pumpkin ------------- */
  391.     int     mojip[22][2];
  392.     char moji[22][20];
  393.  
  394.     set24h();
  395. /* ---------------------------------------------------------- */
  396. /* ------------------ Debug  92.02.07 Pumpkin --------------- */
  397.     retdir(firstdir);
  398. /* ---------------------------------------------------------- */
  399.  
  400. #ifdef    FMR70
  401.     signal(SIGINT,SIG_IGN);
  402. #endif
  403.  
  404.     while ( --argc > 0 ) {
  405.     p = *(++argv);
  406.     if ( *p == '-' || *p == '/' ) {
  407.         switch(*(++p)) {
  408.         case 'A': case 'a':
  409.             Auto_log_file = ++p;
  410.             break;
  411.         case 'B': case 'b':
  412.             Back_up = TRUE;
  413.             break;
  414.         case 'Z': case 'z':
  415.             Apend_Z = TRUE;
  416.             break;
  417. /* ------------------ OAK4 91.12.28 Pumpkin ----------------- */
  418.         case 'R': case 'r':
  419.                 kan_mode = TRUE;
  420.                 modeW = modeW & ~0x30l;
  421.                 modeW = modeW | KAN_ROUMAZI;
  422.             break;
  423.         case 'F': case 'f':
  424.                 kan_mode = TRUE;
  425.                 modeW = modeW & ~0xc0l;
  426.                 modeW = modeW | KAN_ZENKAKU;
  427.             break;
  428.         case 'K': case 'k':
  429.                 kan_mode = TRUE;
  430.                 modeW = modeW & ~0x700l;
  431.                 modeW = modeW | KAN_KATAKANA;
  432.             break;
  433.         case 'H': case 'h':
  434.                 kan_mode = TRUE;
  435.                 modeW = modeW & ~0x700l;
  436.                 modeW = modeW | KAN_HIRAGANA;
  437.             break;
  438.         case 'C': case 'c':
  439.                 kan_mode = TRUE;
  440.                 modeW = modeW & ~0x20000l;
  441.                 modeW = modeW | KAN_EIDAI;
  442.             break;
  443. /* ---------------------------------------------------------- */
  444. /**************************************************
  445.         case 'R': case 'r':
  446.             modeW = (modeW & 0xFFF3) | 0x0008;
  447.             break;
  448.         case 'F': case 'f':
  449.             modeW = (modeW & 0xFFCF) | 0x0020;
  450.             break;
  451.         case 'K': case 'k':
  452.             modeW = (modeW & 0xFE3F) | 0x0080;
  453.             break;
  454.         case 'H': case 'h':
  455.             modeW = (modeW & 0xFE3F) | 0x0100;
  456.             break;
  457. **************************************************/
  458.         case 'T': case 't':
  459.             Tmp_device_name = ++p;
  460.             break;
  461.         case 'D': case 'd':
  462.             TAB = atoi(++p);
  463.             break;
  464. /* --------------- Color Pal   91.08.28 Pumpkin ------------- */
  465. #ifdef    TOWNS
  466.         case 'P': case 'p':
  467.             pal_file = ++p;
  468.             break;
  469. #endif
  470. /* ---------------------------------------------------------- */
  471. /* ------------------ CD No Stop 91.10.18 Pumpkin ----------- */
  472. #ifdef    TOWNS
  473.         case 'N': case 'n':
  474.             cd_stop = FALSE;
  475.             break;
  476. #endif
  477.  
  478. /* ---------------------------------------------------------- */
  479.  
  480.  
  481.         }
  482.     } else
  483.         file = p;
  484.     }
  485.  
  486. /* ------------------ OAK4 91.12.28 Pumpkin ----------------- */
  487.     Gra_init(kan_mode);
  488. /*******
  489.     Gra_init();
  490. *******/
  491. /* ---------------------------------------------------------- */
  492. /* --------------- Color Pal   91.08.28 Pumpkin ------------- */
  493. #ifdef    TOWNS
  494.     pal_init(pal_file);
  495. #endif
  496. /* ---------------------------------------------------------- */
  497. /* --------------- RSB for L20 92.12.27 Pumpkin ------------- */
  498.     RSB_start();
  499. /*******
  500.     RSB_Init();
  501. *******/
  502.     Dsp_init();
  503. /* ------------------ KYB init 92.03.20 Pumpkin ------------- */
  504.     for (i=1;i<21;i++) 
  505.         KYB_rdasign(&mojip[i][1],0x8000+i,&mojip[i][0],&moji[i][0]);
  506.     KYB_rdasign(&mojip[21][1],0x7f,&mojip[21][0],&moji[21][0]);
  507.     KYB_asign(0,0x7f,1,"\x7f");
  508.     KYB_setbuf(1);
  509. /********
  510.     KYB_clic(1);
  511. ********/
  512. /* ---------------------------------------------------------- */
  513.     Auto_log_init();
  514.     Dsp_status();
  515.     Start_Msg();
  516.  
  517.     if ( Bfp_init() != FALSE ) {
  518.     wrtstr("メモリ管理の初期化に失敗しました",30,1,0x12);
  519.     exit(0);
  520.     }
  521.     if ( Buf_init(file) != FALSE ) {
  522.     wrtstr("ファイルの初期化に失敗しました",30,1,0x12);
  523.     exit(0);
  524.     }
  525.  
  526.     Dsp_status();
  527.     Set_vram();
  528.     Dsp_vram(vram);
  529.  
  530.     if ( (i = setjmp(mark)) != 0 ) {
  531.     sprintf(tmp,"致命的なエラ-が発生しました #%d",i);
  532.     wrtstr(tmp,30,1,0x12);
  533.     }
  534.  
  535. /* ------------------ SIDEWORK 92.01.31 Pumpkin ------------- */
  536.     mwork = (char *)malloc(4096);
  537.     MOS_start(mwork,4096);
  538.     sdk_control(0);    /* ホットキーによるサイドワーク起動の禁止 */
  539. /* ---------------------------------------------------------- */
  540.  
  541.     do {
  542.         while ( edit() == FALSE );
  543.     } while ( Del_wind() == FALSE );
  544.  
  545. /* --------------------- EUP play 92.03.30 ------------------ */
  546.     ML_End();                /* customaized by YAMA */
  547. /* ---------------------------------------------------------- */
  548.     Bfp_end();
  549.     RSB_end();
  550. /* ------------------ KYB init 92.03.20 Pumpkin ------------- */
  551.     KYB_init();
  552.     for (i=1;i<21;i++) 
  553.         KYB_asign(mojip[i][1],0x8000+i,mojip[i][0],&moji[i][1]);
  554.     KYB_asign(mojip[21][1],0x7f,mojip[21][0],&moji[21][1]);
  555. /* ---------------------------------------------------------- */
  556.     KYB_clic(1);
  557.  
  558. #ifdef    TOWNS
  559.     CD_endof();
  560. /* ------------------ SIDEWORK 92.01.31 Pumpkin ------------- */
  561.     MOS_end();
  562.     free(mwork);
  563. /* ---------------------------------------------------------- */
  564. /* --------------------- EUP play 92.03.30 ------------------ */
  565.     SND_end();                /* customaized by YAMA */
  566. /* ---------------------------------------------------------- */
  567.     KAN_disp(KAN_DISPOFF);
  568.     KAN_finish();
  569.     RSB_End();
  570. /* --------------- Color Pal   91.12.29 Pumpkin ------------- */
  571.     EGB_init(work,EgbWorkSize);
  572. /* ---------------------------------------------------------- */
  573. #endif
  574. /* ------------------ Debug  92.02.07 Pumpkin --------------- */
  575.     if (diskReady(firstdir[0] - 'A' + 1) == FALSE) 
  576.         chdir(firstdir);
  577.     reset24h();
  578. /* ---------------------------------------------------------- */
  579.  
  580. #ifdef    FMR70
  581.     cprintf("\x1B[2J");
  582. #endif
  583. }
  584.  
  585. #ifdef    FMR70
  586. #include    <dos.h>
  587.  
  588. int     KYB_clic(sw);
  589. int    sw;
  590. {
  591.     union REGS    regs;
  592.  
  593.     regs.h.ah = 0x05;
  594.     regs.h.al = sw;
  595.     int86(0x90,®s,®s);
  596.     return;
  597. }
  598. int    kbhit()
  599. {
  600.     union REGS    regs;
  601.  
  602.     regs.h.ah = 0x07;
  603.     int86(0x90,®s,®s);
  604.     return (int)regs.h.al;
  605. }
  606. int    KYB_read(sw,ec)
  607. int    sw;
  608. unsigned *ec;
  609. {
  610.     union REGS    regs;
  611.  
  612.     regs.h.ah = 0x09;
  613.     regs.h.al = sw;
  614.     int86(0x90,®s,®s);
  615.     *ec = regs.x.bx;
  616.     if ( *ec >= 0x5D00 && *ec <= 0x6600 ) {
  617.         regs.h.ah = 0x09;
  618.         regs.h.al = sw;
  619.         int86(0x90,®s,®s);
  620.         *ec = regs.x.bx;
  621.     }
  622.     return regs.x.dx;
  623. }
  624. #endif
  625.  
  626. /* --------------- Color Pal   91.08.28 Pumpkin ------------- */
  627. /* --------------- Color Pal   91.12.29 Pumpkin ------------- */
  628. #ifdef TOWNS
  629. void pal_init(char *pal_file)
  630. {
  631.     int        n=0,r=0,g=0,b=0,i,num;
  632.     FILE *pfp;
  633.  
  634.     struct _pal_body {
  635.         long    num;
  636.         char    dat[8*16];
  637.     } pal_body;
  638.  
  639.  
  640.     if (pal_file == NULL) return;
  641.     EGB_getPalette(0,(char *)&pal_body);
  642.  
  643.     if ( (pfp = fopen(pal_file,"r")) != NULL ) {
  644.     if (fscanf( pfp, "%d",&num ) == 1 &&  num>0 && num<17 ) {
  645.         for(i=0; i<num; i++) {
  646.                 fscanf( pfp, "%d %d %d %d",&n,&b,&r,&g ); 
  647.             if ( n<16 ) {
  648.             pal_body.dat[n*8  ] = (long)n;
  649.             pal_body.dat[n*8+4] = (char)b*16;
  650.             pal_body.dat[n*8+5] = (char)r*16;
  651.             pal_body.dat[n*8+6] = (char)g*16;
  652.             }
  653.             }
  654.         }
  655.     fclose( pfp );
  656.     }
  657.     EGB_writePage(work, 0);
  658.     EGB_palette(work,1,(char *)&pal_body);
  659.  
  660. }
  661.  
  662. #endif
  663. /* ---------------------------------------------------------- */
  664.